#!/bin/sh
#
# Create a skelton of a new data class in labman2

# You need to change DIR to your labman2 base directory.

if [ $# != 1 ]
then 
  echo "Should have 1 parameter, name of the new class."
  exit 1
fi

DIR=~chu/progs/labman2
SUBDIR=labman2/data/subdata
CLASS=${1}
LCLASS=`echo $CLASS | tr [:upper:] [:lower:]`

echo $DIR $SUBDIR
echo $CLASS $LCLASS

cd $DIR/$SUBDIR
$DIR/manage.py startapp $CLASS
mkdir $CLASS/sql
echo "BEGIN;" > $CLASS/sql/$LCLASS.sql
echo "INSERT INTO data_classes (classname) VALUES" >> $CLASS/sql/$LCLASS.sql
echo "  ('$CLASS');" >> $CLASS/sql/$LCLASS.sql
echo "COMMIT;" >> $CLASS/sql/$LCLASS.sql

$DIR/manage.py syncdb

echo "You might want do remove some files like follows"
echo "rm $DIR/$SUBDIR/$CLASS/views.py $DIR/$SUBDIR/$CLASS/admin.py $DIR/$SUBDIR/$CLASS/tests.py"
